
'use strict';

define(['app'], function (app) {
        app.config(function($stateProvider, $urlRouterProvider, $controllerProvider){
            app.registerController = $controllerProvider.register;
            app.loadJs = function(js){
                return function($rootScope, $q){
                    var def = $q.defer(),deps=[];
                    angular.isArray(js) ? (deps = js) : deps.push(js);
                    require(deps,function(){
                        $rootScope.$apply(function(){
                            def.resolve();
                        });
                    });
                    return def.promise;
                };
            };

            $urlRouterProvider.otherwise("login");

            $stateProvider.state("login",{
                url : "/login",
                views : {
                    "body" : {
                        templateUrl : "views/login.html",
                        controller : "ctrl.login"
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/system/login")
                }
            });

            $stateProvider.state("index",{
                url : "/index",
                views : {
                    "body" : {
                        templateUrl : "views/index.html",
                        controller : "ctrl.index"
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/system/index")
                }
            });

            //锁定屏幕
            $stateProvider.state("lock",{
                url : "/lock",
                views : {
                    "body" : {
                        templateUrl : "views/lock.html",
                        controller : "ctrl.lock"
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/system/lock")
                }
            });

            //home
            $stateProvider.state("index.home",{
                url : "/home",
                views : {
                    "mainContent" : {
                        templateUrl : "views/home/home.html",
                        controller : "ctrl.home"
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/home/home")
                }
            });

            //航班动态
            //航班动态列表
            $stateProvider.state("index.flightDynaList",{
                url : "/flightDynamic/dynamicList",
                views : {
                    "mainContent" : {
                        templateUrl : "views/flight-dynamic/flight-dynamic-list.html",
                        controller : "ctrl.FlightDynamic.dynaList"
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/flightDynamic/dynamicList")
                }
            });


            //个人信息
            $stateProvider.state("index.profile",{
                url : "/user/profile",
                views : {
                    "mainContent" : {
                        templateUrl : 'views/user/user-profile.html',
                        controller : 'ctrl.user.profile'
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/user/profile')
                }
            });

            //个人日历
            $stateProvider.state("index.calendar",{
                url : "/user/calendar",
                views : {
                    "mainContent" : {
                        templateUrl : 'views/user/user-calendar.html',
                        controller : 'ctrl.calendar'
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/user/calendar')
                }
            });

            //个人消息
            $stateProvider.state("index.mail",{
                url : "/user/mail",
                views : {
                    "mainContent": {
                        templateUrl : "views/user/user-mail.html",
                        controller : "ctrl.user.mail"
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/user/mail')
                }
            });

            //飞机管理
            //添加机型
            $stateProvider.state("index.addAircraft",{
                url : '/aircraft/addAircraft',
                views : {
                    "mainContent" : {
                        templateUrl : 'views/aircraft/add-aircraft-type.html',
                        controller : 'ctrl.aircraft.addAircraft'
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/aircraft/addAircraft')
                }
            });

            //机型列表
            $stateProvider.state("index.aircraftList",{
                url : '/aircraft/aircraftList',
                views : {
                    "mainContent" : {
                        templateUrl : 'views/aircraft/aircraft-list.html',
                        controller : 'ctrl.aircraft.aircraftList'
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/aircraft/aircraftList')
                }
            });

            //添加飞机制造商
            $stateProvider.state("index.airCompany",{
                url : '/aircraft/airCompany',
                views : {
                    "mainContent" : {
                        templateUrl : 'views/aircraft/add-manufacturer.html',
                        controller : 'ctrl.aircraft.airCompany'
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/aircraft/airCompany')
                }
            });

            //编辑飞机制造商
            $stateProvider.state("index.airCompany.a",{
                url : '/edit',
                views : {
                    "alert" : {
                        templateUrl : 'views/aircraft/edit-air-company.html',
                        controller : 'ctrl.aircraft.airCompany'
                    }
                }
            });

            $stateProvider.state('makeFlightPlan',{
                url : '/makeFlightPlan',
                templateUrl : 'views/flight/make-flight-plan.html',
                controller : 'ctrl.makeFlightPlan',
                resolve:{
                    deps:app.loadJs('./controller/flight/makeFlightPlan')
                }
            });



            //公告系统
            //发布公告
            $stateProvider.state("index.addNotice",{
                url : '/notice/add',
                views : {
                    "mainContent" : {
                        templateUrl : "views/notice/create-notice.html",
                        controller : 'ctrl.notice.add'
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/notice/createNotice")
                }
            });
            //公告管理
            $stateProvider.state("index.noticeList",{
                url : '/notice/list',
                views : {
                    "mainContent" : {
                        templateUrl : "views/notice/notice-list.html",
                        controller : 'ctrl.notice.list'
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/notice/noticeList")
                }
            });


            //飞行计划
            //编辑航路
            $stateProvider.state("index.editRoute",{
                url : '/route/editRoute',
                views : {
                    "mainContent" : {
                        templateUrl : "views/route/edit-route.html",
                        controller : 'ctrl.route.editRoute'
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/route/editRoute")
                }
            });

            //气象信息预报
            //机场天气
            $stateProvider.state("index.airportWeather",{
                url : '/weather/airportWeather',
                views : {
                    "mainContent" : {
                        templateUrl : "views/weather/airport-weather.html"
                    }
                }
            });

            //航路天气
            $stateProvider.state("index.airwayWeather",{
                url : '/weather/airwayWeather',
                views : {
                    "mainContent" : {
                        templateUrl : "views/weather/air-route-weather.html"
                    }
                }
            });

            //航班管理
            //添加航班计划
            $stateProvider.state("index.addFlightSchedule",{
                url : '/flight/addFlightSchedule',
                views : {
                    "mainContent" : {
                        templateUrl : "views/flight/add-flight-schedule.html",
                        controller : 'ctrl.addFlight'
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/flight/addFlightSchedule")
                }
            });

            //航班计划列表
            $stateProvider.state("index.flightScheduleList",{
                url : '/flight/flightScheduleList',
                views : {
                    "mainContent" : {
                        templateUrl : "views/flight/flight-schedule-list.html",
                        controller : 'ctrl.flightScheduleList'
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/flight/flightScheduleList")
                }
            });

            //机场信息维护
            //机场航图
            $stateProvider.state("index.airChart",{
                url : '/airport/airChart',
                views : {
                    "mainContent" : {
                        templateUrl : "views/airport/air-chart.html",
                        controller : 'ctrl.airChart'
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/airport/airChart")
                }
            });

            //机场信息查询
            $stateProvider.state("index.airportInfo",{
                url : '/airport/airportInfo',
                views : {
                    "mainContent" : {
                        templateUrl : "views/airport/airport-info.html",
                        controller : 'ctrl.airport.airportInfo'
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/airport/airportInfo")
                }
            });

            //添加机场
            $stateProvider.state("index.addAirport",{
                url : '/airport/addAirport',
                views : {
                    "mainContent" : {
                        templateUrl : "views/airport/add-airport.html",
                        controller : 'ctrl.airport.addAirport'
                    }
                },
                resolve:{
                    deps:app.loadJs("./controller/airport/addAirport")
                }
            });


            //用户管理
            //添加用户
            $stateProvider.state("index.addUser",{
                url : "/userManager/addUser",
                views : {
                    "mainContent": {
                        templateUrl : "views/user-manager/add-user.html",
                        controller : "ctrl.userManager.addUser"
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/userManager/addUser')
                }
            });
            //权限管理
            //权限列表
            $stateProvider.state("index.permission",{
                url : "/perManager/permission",
                views : {
                    "mainContent": {
                        templateUrl : "views/per-manager/permission.html",
                        controller : "ctrl.perManager.permission"
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/perManager/permission')
                }
            });
            //添加权限
            $stateProvider.state("index.add-permission",{
                url : "/perManager/add-permission",
                views : {
                    "mainContent": {
                        templateUrl : "views/per-manager/add-permission.html",
                        controller : "ctrl.perManager.add-permission"
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/perManager/add-permission')
                }
            });
            //系统日志
            $stateProvider.state("index.syslog",{
                url : "/sysLog/syslog",
                views : {
                    "mainContent": {
                        templateUrl : "views/syslog/syslog.html",
                        controller : "ctrl.sysLog.syslog"
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/sysLog/syslog')
                }
            });


            //制作飞行计划
            $stateProvider.state("index.makeFlightPlan",{
                url : "/flight/makeFlightPlan",
                views : {
                    "mainContent": {
                        templateUrl : "views/flight/make-flight-plan.html",
                        controller : "ctrl.flight.makeFlightPlan"
                    }
                },
                resolve:{
                    deps:app.loadJs('./controller/flight/makeFlightPlan')
                }
            });


        });

});

